package academic.concordia.bankofquebec.dao.bill;

import java.util.List;

import org.hibernate.SessionFactory;

import academic.concordia.bankofquebec.entity.Bill;
import academic.concordia.bankofquebec.entity.Client;

public class BillDAO implements IBillDAO {
	
	private SessionFactory sessionFactory;

	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	@Override
	public void addBill(Bill bill) {
		getSessionFactory().getCurrentSession().save(bill);
	}

	@Override
	public void updateBill(Bill bill) {
		getSessionFactory().getCurrentSession().update(bill);
	}

	@Override
	public void deleteBill(Bill bill) {
		getSessionFactory().getCurrentSession().delete(bill);
	}
	
	@Override
	public Bill getBillById(String id) {
		List<?> list = getSessionFactory().getCurrentSession().createQuery("from Client where reference=?").setParameter(0, id).list();
		return (Bill)list.get(0);
	}
}
